package cn.iocoder.yudao.module.jikong.dal.mysql.jkOrder;

import java.util.*;
import java.util.stream.Collectors;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.jikong.dal.dataobject.jkOrder.JkOrderDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.jikong.controller.admin.jkOrder.vo.*;

/**
 * 单据 Mapper
 *
 * @author xc
 */
@Mapper
public interface JkOrderMapper extends BaseMapperX<JkOrderDO> {

    default PageResult<JkOrderDO> selectPage(JkOrderPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<JkOrderDO>()
                .likeIfPresent(JkOrderDO::getOrderNo, reqVO.getOrderNo())
                .eqIfPresent(JkOrderDO::getUserId, reqVO.getUserId())
                .likeIfPresent(JkOrderDO::getUserPhone, reqVO.getUserPhone())
                .eqIfPresent(JkOrderDO::getUserType, reqVO.getUserType())
                .eqIfPresent(JkOrderDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(JkOrderDO::getReceiveTime, reqVO.getReceiveTime())
                .betweenIfPresent(JkOrderDO::getRebackTime, reqVO.getRebackTime())
                .betweenIfPresent(JkOrderDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(JkOrderDO::getId));
    }

    default PageResult<JkOrderDO> selectPageExpert(JkOrderPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<JkOrderDO>()
                .likeIfPresent(JkOrderDO::getOrderNo, reqVO.getOrderNo())
                .eqIfPresent(JkOrderDO::getUserId, reqVO.getUserId())
                .likeIfPresent(JkOrderDO::getUserPhone, reqVO.getUserPhone())
                .eqIfPresent(JkOrderDO::getUserType, reqVO.getUserType())
                .eqIfPresent(JkOrderDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(JkOrderDO::getReceiveTime, reqVO.getReceiveTime())
                .betweenIfPresent(JkOrderDO::getRebackTime, reqVO.getRebackTime())
                .betweenIfPresent(JkOrderDO::getCreateTime, reqVO.getCreateTime())
                .ne(JkOrderDO::getStatus,1)
                .orderByDesc(JkOrderDO::getId)
        );
    }


    //select type,count(1) as count from jk_order group by type;
    List<Map<String, Long>> selectStatusCountByStatus();

}
